package com.example.spzx.controller;

import com.example.spzx.Service.SysUserService;
import com.example.spzx.model.dto.system.AssginRoleDto;
import com.example.spzx.model.dto.system.SysUserDto;
import com.example.spzx.model.entity.system.SysUser;
import com.example.spzx.model.vo.common.Result;
import com.example.spzx.model.vo.common.ResultCodeEnum;
import com.github.pagehelper.PageInfo;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/admin/system/sysUser")
public class SysUserController {
    @Resource
    private SysUserService sysUserService;
    @GetMapping("/findByPage/{pageNum}/{pageSize}")
    public Result<SysUser> findByPage(SysUserDto sysUserDto, @PathVariable("pageNum") Integer pageNum, @PathVariable("pageSize") Integer pageSize){
        PageInfo<SysUser> pageInfo=sysUserService.list(sysUserDto,pageNum,pageSize);
        return Result.build(pageInfo, ResultCodeEnum.SUCCESS);
    }
    @PostMapping("/add")
    public Result<SysUser> add(@RequestBody SysUser sysUser){
        sysUserService.add(sysUser);
        return Result.build(null,ResultCodeEnum.SUCCESS);
    }
    @PostMapping("/update")
    public Result<SysUser> update(@RequestBody SysUser sysUser){
        sysUserService.update(sysUser);
        return Result.build(null,ResultCodeEnum.SUCCESS);
    }
    @GetMapping("/delete/{id}")
    public Result<SysUser> delete(@PathVariable("id") Integer id){
        sysUserService.delete(id);
        return Result.build(null,ResultCodeEnum.SUCCESS);
    }
    @GetMapping("/showrole/{id}")
    public Result<List<Integer>> showrole(@PathVariable("id") Integer id){
        return Result.build(sysUserService.selectrole(id),ResultCodeEnum.SUCCESS);
    }
    @PostMapping("/setrole")
    public Result<SysUser> setrole(@RequestBody AssginRoleDto assginRoleDto){
        sysUserService.setrole(assginRoleDto);
        return Result.build(null,ResultCodeEnum.SUCCESS);

    }
}
